//
//  WYCBillController.m
//  51还款
//
//  Created by 中企互联 on 2017/10/30.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "WYCBillController.h"
#import "PictureRotate.h"
#import "CCPScrollView.h"
#import "CCZTrotingLabel.h"
#import "WYCMymessegeController.h"
#import "HWRollingView.h"
#import "WYCPictureModel.h"
#import "WYCBillModel.h"
#import "WYCHomeCell.h"
#import "WYCBillFrameModel.h"
#import "WYCSeeBillController.h"
#import "WYCUserMessegeModel.h"
#import "WYCAddCreditController.h"
#import "XMGVerticalButton.h"
#import "WYCHuankuanViewController.h"
#import "WYCmyCardCotroller.h"
#import "WYCbankcardViewController.h"
#import "WYCFastCspController.h"
#import "WYCSetDissController.h"
#import "WYCMessegeModel.h"
@interface WYCBillController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) CCZTrotingLabel *trotView;

@property(nonatomic,strong)NSMutableArray * imageArray;
/** 列表*/
@property(nonatomic,strong)UIScrollView * scrollView;

/** 数组*/
@property(nonatomic,strong)NSMutableArray * billarray;

/** 图片*/
@property(nonatomic,strong)UIImageView * backimg;

/** 提示*/
@property(nonatomic,strong)UILabel * backLabel;

/** 按钮*/
@property(nonatomic,strong)UIButton * ImportButton;

/** view*/
@property(nonatomic,strong)UIView * billView;
@property(nonatomic,strong)UIView * buttonView;

@property(nonatomic,strong)UIView * showView;

/** 数组*/
@property(nonatomic,strong)NSMutableArray * showArray;

@property (nonatomic,strong) CCZTrotingLabel *label;
@property(nonatomic,strong) XMGVerticalButton * billButton;
@property(nonatomic,strong) XMGVerticalButton * CardButton;
@property(nonatomic,strong) XMGVerticalButton * BuyingButton;
@property(nonatomic,strong) XMGVerticalButton * packageButton;
@property(nonatomic,strong) XMGVerticalButton * FangButton;
@property(nonatomic,strong) XMGVerticalButton * NetloanButton;
@property(nonatomic,strong)UIView * buttonView1;
@property(nonatomic,strong) UIImageView * imageView1;
@property(nonatomic,strong) UIImageView * imageView2;

@end

@implementation WYCBillController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WYCGlobalBg;
    //图片数组
    self.imageArray = [[NSMutableArray alloc] init];
    self.showArray = [[NSMutableArray alloc] init];
    [self setusermyMessage];
    [self setupIMG];
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _scrollView.backgroundColor = WYCGlobalBg;
    _scrollView.delegate = self;
    _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight+100);
    _scrollView.userInteractionEnabled = YES;
    [self.view addSubview:_scrollView];

}

- (void)setusermyMessage{
    
    NSString * str = [NSString stringWithFormat:@"%@token=%@",messagelist,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);

        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            NSDictionary * dic = responseObject[@"result"];
            NSArray * dataArray = dic[@"data"];
            for (NSDictionary * dict in dataArray) {
                WYCMessegeModel * messegeModel = [WYCMessegeModel mj_objectWithKeyValues:dict];
                [self.showArray addObject:messegeModel.title];
            }
                       [self shownotion];

        }else{
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
            
        }
//        if ([[responseObject objectForKey:@"code"]intValue] == 0) {
//
//            [self hideLoading];
//            NSArray * resultArray = responseObject[@"result"];
//            for (NSDictionary * dict in resultArray) {
//                WYCUserMessegeModel * usermodel = [WYCUserMessegeModel mj_objectWithKeyValues:dict];
//                [self.showArray addObject:usermodel.content];
//
//            }
//            [self shownotion];
//
//        }else{
//            [self hideLoading];
//            [self showToast:msgStr];
//        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [self showToast:Failed];
        [self hideLoading];
    }];
    
}

- (void)ObtainButton{
    
    self.billView = [[UIView alloc] init];
    self.billView.frame = CGRectMake(ScreenWidth / 3 - 50 * px, ScreenHeight / 2 + 200 * px, ScreenWidth / 3 + 100 * px, ScreenWidth / 3);
    self.billView.backgroundColor = WYCGlobalBg;
    [self.view addSubview:self.billView];
    
    _backimg = [[UIImageView alloc] init];
    _backimg.image = [UIImage imageNamed:@"home_photo"];
    _backimg.frame = CGRectMake(0, 0, self.billView.width / 2 - 103 * px,225 * px);
    [self.billView addSubview:_backimg];
    
    
    _backLabel = [[UILabel alloc] init];
    _backLabel.text = @"还没有账单信息哟~";
    _backLabel.textAlignment = NSTextAlignmentCenter;
    _backLabel.font = [UIFont systemFontOfSize:SmallFont];
    _backLabel.textColor = WYCRGBColor(186, 186, 186);
    _backLabel.frame = CGRectMake(_backimg.x,CGRectGetMaxY(_backimg.frame) + 10 * px,_backimg.width,48 * px);
    [self.billView addSubview:_backLabel];
    
    
    _ImportButton = [[UIButton alloc] init];
    _ImportButton.frame = CGRectMake(_backLabel.x + 50 * px, CGRectGetMaxY(_backLabel.frame) + 80 * px, _backLabel.width - 100 * px , 100 * px);
    [_ImportButton setTitle:@"导入账单" forState:UIControlStateNormal];
    [_ImportButton addTarget:self action:@selector(importClick) forControlEvents:UIControlEventTouchUpInside];
    _ImportButton.backgroundColor = [UIColor whiteColor];
    _ImportButton.titleLabel.font = [UIFont systemFontOfSize:MiddleFont];
    [_ImportButton setTitleColor:WYCRGBColor(195, 195, 195) forState:UIControlStateNormal];
    [self.billView addSubview:_ImportButton];
}
#pragma make ------->>>轮播图
- (void)setupIMG{
    
    [HttpTool POST:bannerlist params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            NSArray * resultarray = responseObject[@"result"];
            WYCLog(@"------------%@",responseObject);
            for (NSDictionary * dict in resultarray) {
                
                WYCPictureModel * model = [WYCPictureModel mj_objectWithKeyValues:dict];
                [self.imageArray addObject:model.imgUrl];
            }
            [self initImageNamesSystemPageControlAndTitle];
            
        }else{
            
            [self showToast:msgStr];
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [self showToast:Failed];
    }];
}

- (void)shownotion{
    
    //通知的View
    _showView = [[UIView alloc] init];
    _showView.frame = CGRectMake(0, 550 * px+30, ScreenWidth, 50);
    _showView.userInteractionEnabled = YES;
    _showView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_showView];

    //通知imageView
    UIImageView *noticeimageView = [[UIImageView alloc] init];
    noticeimageView.frame = CGRectMake(80 * px, 20, 40 * px, 40 * px);
    noticeimageView.image = [UIImage imageNamed:@"提醒"];
    [_showView addSubview:noticeimageView];


    UIView * duanView = [[UIView alloc] init];
    duanView.backgroundColor = WYCRGBColor(205, 205, 205);
    duanView.frame = CGRectMake(CGRectGetMaxX(noticeimageView.frame) + 40 * px, 40 * px, 0.5, _showView.height - 40 * px);
    [_showView addSubview:duanView];

    self.label = [[CCZTrotingLabel alloc] init];
    self.label.frame = CGRectMake(CGRectGetMaxX(duanView.frame) + 40 * px, 40 * px, ScreenWidth - noticeimageView.width - 120 * px, 80 * px);
    self.label.direction = CCZTrotDirectionTop;
    self.trotView = self.label;
    self.label.repeatTextArr = YES;
    self.label.hideWhenStopTroting = YES;
    self.label.pause = 4;
    [self.label addTextArray:self.showArray];
    //    self.label.backgroundImage = [UIImage imageNamed:@"1"];
    [_showView addSubview:self.label];
    UITapGestureRecognizer *tapRecognizerWeibo=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoClick)];
    
    self.label.userInteractionEnabled=YES;
    [self.label addGestureRecognizer:tapRecognizerWeibo];
    _buttonView = [[UIView alloc] init];
    _buttonView.frame = CGRectMake(0,_showView.frame.size.height+_showView.frame.origin.y+10, ScreenWidth, 700 * px);
    _buttonView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_buttonView];

   _billButton = [[XMGVerticalButton alloc] init];
    _billButton.frame = CGRectMake(0, 40 * px, ScreenWidth/3, 280 * px);
    [_billButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_billButton addTarget:self action:@selector(billButtonClick)
         forControlEvents:UIControlEventTouchUpInside];
    _billButton.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
    [_billButton setTitle:@"智能还款" forState:UIControlStateNormal];
    [_billButton setImage:[UIImage imageNamed:@"huankuan"] forState:UIControlStateNormal];
    [_buttonView addSubview:_billButton];



    _packageButton = [[XMGVerticalButton alloc] init];
    _packageButton.frame = CGRectMake(ScreenWidth/3*2, _billButton.y, ScreenWidth/3, 280 * px);

    [_packageButton addTarget:self action:@selector(packageButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_packageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_packageButton setTitle:@"更多" forState:UIControlStateNormal];
    [_packageButton setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
    [_buttonView addSubview:_packageButton];

  

      _BuyingButton = [[XMGVerticalButton alloc] init];
    _BuyingButton.frame = CGRectMake(0, CGRectGetMaxY(_billButton.frame) + 50 * px, ScreenWidth/3, 280 * px);
    [_BuyingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [_BuyingButton addTarget:self action:@selector(BuyingButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_BuyingButton setTitle:@"信用卡申请" forState:UIControlStateNormal];
    [_BuyingButton setImage:[UIImage imageNamed:@"main_bottom_bg"] forState:UIControlStateNormal];
    [_buttonView addSubview:_BuyingButton];

    _CardButton= [[XMGVerticalButton alloc] init];
    _CardButton.frame = CGRectMake(ScreenWidth/3, _BuyingButton.y, ScreenWidth/3, 280 * px);

    [_CardButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_CardButton setTitle:@"消费/收款" forState:UIControlStateNormal];
    [_CardButton addTarget:self action:@selector(CardButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_CardButton setImage:[UIImage imageNamed:@"xiaofei"] forState:UIControlStateNormal];
    [_buttonView addSubview:_CardButton];

     _FangButton = [[XMGVerticalButton alloc] init];
    _FangButton.frame = CGRectMake(ScreenWidth/3 ,40 * px , ScreenWidth/3, 280 * px);

    [_FangButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_FangButton setTitle:@"拨打客服" forState:UIControlStateNormal];
    [_FangButton addTarget:self action:@selector(FangButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_FangButton setImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
    [_buttonView addSubview:_FangButton];


    _NetloanButton = [[XMGVerticalButton alloc] init];
    _NetloanButton.frame = CGRectMake(ScreenWidth/3*2, _BuyingButton.y,ScreenWidth/3, 280 * px);
    [_NetloanButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_NetloanButton addTarget:self action:@selector(NetloanButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [_NetloanButton setTitle:@"积分商城" forState:UIControlStateNormal];
    [_NetloanButton setImage:[UIImage imageNamed:@"shop"] forState:UIControlStateNormal];
    [_buttonView addSubview:_NetloanButton];
    
    _buttonView1 = [[UIView alloc] init];
    _buttonView1.frame = CGRectMake(0,_buttonView.frame.size.height+_buttonView.frame.origin.y+10, ScreenWidth, 600 * px);
    _buttonView1.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_buttonView1];
    UIView  *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 5, 5, 20)];
    lineView.backgroundColor = wycMain;
    [_buttonView1 addSubview:lineView];
    UILabel  *recom = [[UILabel alloc]init];
    recom.frame = CGRectMake(20, 5, 120, 20);
    recom.text = @"精彩推荐";
    recom.font = [UIFont systemFontOfSize:13];
    recom.textColor = wycMain;
    [_buttonView1 addSubview:recom];
    
    _imageView1= [[UIImageView alloc] init];
    _imageView1.frame = CGRectMake(0, recom.frame.size.height+recom.frame.origin.y+5, ScreenWidth, 130);
    _imageView1.image = [UIImage imageNamed:@"bgone"];
    [_buttonView1 addSubview:_imageView1];
    _imageView2 = [[UIImageView alloc] init];
    _imageView2.frame = CGRectMake(0, _imageView1.frame.size.height+_imageView1.frame.origin.y, ScreenWidth, 130);
    _imageView2.image = [UIImage imageNamed:@"bgtwo"];
    [_buttonView1 addSubview:_imageView2];
    [self loadversion];

}
//积分商城
-(void)NetloanButtonClick
{
    [self showToast:@"努力开发中..."];
    return;
}
//智能还款
-(void)billButtonClick
{
    WYCHuankuanViewController *huanView = [[WYCHuankuanViewController alloc]init];
    [self.navigationController pushViewController:huanView animated:YES];
}
//更多
-(void)packageButtonClick
{
    WYCSetDissController *setView = [[WYCSetDissController alloc]init];
    [self.navigationController pushViewController:setView animated:YES];
}
//拨打客服
-(void)FangButtonClick
{
    UIAlertController *alertController =  [UIAlertController alertControllerWithTitle:@"联系我们" message:@"400-822-7776" preferredStyle:UIAlertControllerStyleAlert];
    
    //添加取消到UIAlertController中
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:cancelAction];
    
    //添加确定到UIAlertController中
    UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了好的按钮");
        NSString *allString = [NSString stringWithFormat:@"tel:400-822-7776"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]];
        
    }];
    
    [alertController addAction:OKAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
//信用卡申请
-(void)BuyingButtonClick
{
    WYCbankcardViewController *bankView = [[WYCbankcardViewController alloc]init];
    [self.navigationController pushViewController:bankView animated:YES];
}
//消费、收款
-(void)CardButtonClick
{
    WYCFastCspController  *fastView = [[WYCFastCspController alloc]init];
    fastView.myFlag = @"333";
    [self.navigationController pushViewController:fastView animated:YES];
}
/**
 *  使用本地图片、系统PageControl、设置标题
 */
- (void)initImageNamesSystemPageControlAndTitle {
    
    UIView * cellview = [[UIView alloc] init];
    cellview.frame = CGRectMake(0, 20, ScreenWidth, 550  * px);
    cellview.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:cellview];
    
    
    HWRollingView * RollingView = [HWRollingView rollingViewWithFrame:CGRectMake(0,20, ScreenWidth, 550 * px) RollingStyle:RollingStyleNetwork Data:self.imageArray];
    [cellview addSubview:RollingView];
    
}


#pragma make ------>>左侧按钮 点击事件
- (void)photoClick{
    WYCMymessegeController * mymessege = [[WYCMymessegeController alloc] init];
    [self.navigationController pushViewController:mymessege animated:NO];
}
- (void)repayMentClick{
    
    [self showToast:@"绑定成功！请耐心等待认证结果或拨打客服电话咨询"];
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    
    
    UIView * NavView = [[UIView alloc] init];
    NavView.frame = CGRectMake(0, 0, ScreenWidth, NavHeight);
    NavView.backgroundColor = WYCmainColor;
    [self.view addSubview:NavView];
    
    CALayer *bottomLineLayer = [[CALayer alloc] init];
    bottomLineLayer.frame = CGRectMake(0, NavView.bounds.size.height - 0.5, NavView.bounds.size.width, 0.5);
    bottomLineLayer.backgroundColor = WYCmainColor.CGColor;
    [NavView.layer addSublayer:bottomLineLayer];
    
    
//    //返回按钮
//    UIButton *  fanhuibutton = [[UIButton alloc] init];
//    [fanhuibutton setImage:[UIImage imageNamed:@"ring"] forState:UIControlStateNormal];
//    [fanhuibutton addTarget:self action:@selector(photoClick) forControlEvents:UIControlEventTouchUpInside];
//    fanhuibutton.frame = CGRectMake(30 * px, titleY, 66 * px , 66 * px);
//    [NavView addSubview:fanhuibutton];
    
    
    UILabel * NavRigsterLabel = [[UILabel alloc] init];
    NavRigsterLabel.frame = CGRectMake(0, titleY, NavView.width, 68 * px);
    NavRigsterLabel.textColor = [UIColor whiteColor];
    NavRigsterLabel.font = [UIFont boldSystemFontOfSize:BigFont];
    NavRigsterLabel.textAlignment = NSTextAlignmentCenter;
    NavRigsterLabel.text = @"掌上还";
    [NavView addSubview:NavRigsterLabel];
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)loadversion
{
    
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    NSLog(@"=======%@",appVersion);
    params[@"version"] = appVersion;
    
    [HttpTool POST:function params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([[responseObject objectForKey:@"code"] intValue ] == 0) {
            NSLog(@"第一%@",responseObject);
//            if ([[responseObject objectForKey:@"result"] intValue ] == 0) {
//                self.NetloanButton.hidden =YES;
//                self.CardButton.hidden =YES;
//                self.BuyingButton.hidden =YES;
//                [_billButton setTitle:@"卡管家" forState:UIControlStateNormal];
//                _buttonView.frame = CGRectMake(0,_showView.frame.size.height+_showView.frame.origin.y+10, ScreenWidth, 350 * px);
//                _buttonView1.frame = CGRectMake(0,_buttonView.frame.size.height+_buttonView.frame.origin.y+10, ScreenWidth, 600 * px);
//                _imageView1.image = [UIImage imageNamed:@"bgxian"];
//                _imageView2.image = [UIImage imageNamed:@"001"];
//
//            }
//            else
//            {
                [_billButton setTitle:@"智能还款" forState:UIControlStateNormal];
                _buttonView.frame = CGRectMake(0,_showView.frame.size.height+_showView.frame.origin.y+10, ScreenWidth, 700 * px);
                _buttonView1.frame = CGRectMake(0,_buttonView.frame.size.height+_buttonView.frame.origin.y+10, ScreenWidth, 600 * px);
                _imageView1.image = [UIImage imageNamed:@"bgone"];
                _imageView2.image = [UIImage imageNamed:@"bgtwo"];

                self.NetloanButton.hidden =NO;
                self.CardButton.hidden =NO;
                self.BuyingButton.hidden =NO;            }
            
      //  }
        
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
        [self showToast:Failed];
    }];
}
@end

